package com.atguigu.tingshu.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class ThreadPoolExecutorConfig {
//    自定义线程池
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
//     工具类创建的线程池要么阻塞队列，要么有个数限制，这里自定义个
        int cpuCoreNum = Runtime.getRuntime().availableProcessors();
        System.out.println("cpuCoreNum:\t"+cpuCoreNum);
        return new ThreadPoolExecutor(
                cpuCoreNum,
                cpuCoreNum*2,
                3,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()

        );
    }

}
